package com.fish.service.impl.passport;

import java.sql.Timestamp;
import java.util.Date;

import com.fish.passport.po.PassCode;
import com.fish.passport.po.PassEvent;
import com.fish.service.passport.ProcessorCallbackService;
import com.fish.vo.Passport;
import com.fish.vo.PassportConstant;
/**
 * 申请回调实现
 * @author chenlinjun
 * @date:2010-9-25 
 */
public class ApplyCodeProcessorCallbackServiceImpl extends ProcessorCallbackService {
	@Override
	public boolean successExecute(PassCode passCode, Passport passport) {
		passCode.setAddCode(passport.getAddCode());
		String addCodeMd5=passport.getAddCodeMd5()==null?"":passport.getAddCodeMd5();
		passCode.setAddCodeMd5(addCodeMd5);
		passCode.setUpdateTime(new Date());
		passCode.setCode(passport.getCode());
		passCode.setStatus(passport.getStatus());
		passCode.setExtId(passport.getExtId()==null?"":passport.getExtId());
		passCode.setSendSms(passport.getSendSms());
		passCode.setSendOrderid(String.valueOf(passport.isSendOrderid()));
		passCode.setStatusNo(null);
		passCode.setReapplyTime(null);
		passCode.setStatusExplanation(passport.getMessageWhenApplySuccess());
		if(passport.getCodeImage()!=null){
			passCode.setCodeImage(passport.getCodeImage());
		}
		//更新通关码信息
		this.passCodeDAO.updatePassCodeBySerialNo(passCode);
		return true;
	}
	
	@Override
	protected boolean errorExecute(PassCode passCode, Passport passport, PassEvent passEvent) {
		passCode.setStatus(passport.getStatus());
		passCode.setStatusNo(PassportConstant.PASSCODE_ERROR.APPLY.name());
		passCode.setStatusExplanation(passport.getZhErrorMessage());
		if(passport.getReapplyTime()!=null){
			passCode.setReapplyTime(new Timestamp(passport.getReapplyTime().getTime()));
		}
		passCodeDAO.updatePassCodeBySerialNo(passCode);
		super.addComLog(passCode, passport.getComLogContent(), "申请通关码失败");
		return true;
	}
}
